
* test scores from age 7 and 11 tests
use "Data/NCDS/UKDA-5565-stata11/stata11/ncds0123.dta", clear
qui ds, not(varl "ncdsid serial number"|varl "1T*" |varl "2T*")
drop `r(varlist)'

* rename serial number
rename ncdsid  NCDSID  

* math skill at 7 
rename n90 math_7
replace  math_7=. if  math_7<0

* reading skill at 7 
rename n92 reading_7
replace reading_7=. if reading_7<0

* verbal general ability skilll at 11
rename n914 verbal_11
replace verbal_11=. if verbal_11<0

* non-verbal general ability skilll at 11 
rename n917 nonverbal_11
replace nonverbal_11=. if nonverbal_11<0

* general ability at 11
ge generalab_11=verbal_11+nonverbal_11

* reading comp at 11 
rename n923 reading_11
replace reading_11=. if reading_11<0

* math skills at 11 
rename n926 math_11
replace math_11=. if math_11<0

* retain information only if have a full set of test scores
local tests  nonverbal_11 verbal_11  generalab_11 math_7 reading_7 reading_11 math_11 
egen NMTS=rowmiss(`tests')

foreach t of local tests{
replace `t'=. if NMTS!=0
}

keep NCDSID *_7 *_11 
sort NCDSID 

save scratchdata/ncds0123_testscores.dta, replace
